
class Singleton(object):
    _Instance = {}

    def __init__(self, cls):
        self.cls = cls

    def __call__(self, *args, **kwargs):
        instance = self._Instance.get(self.cls, None)
        if not instance:
            instance = self.cls(*args, **kwargs)
            self._Instance[self.cls] = instance
        return instance

    def __getattr__(self, item):
        return getattr(self.cls, item, None)


# def singleton(cls, *args, **kwargs):
#     instance = {}
#
#     def _singleton():
#         if cls not in instance:
#             instance[cls] = cls(*args, **kwargs)
#         return instance[cls]
#
#     ret = _singleton()
#     return ret
